import argparse


def calculate(a, b, c):
    if c == 'add':
        return a + b
    elif c == 'subtract':
        return a - b
    elif c == 'multiply':
        return a * b
    elif c == 'divide':
        if b != 0:
            return a / b
        else:
            raise ValueError("除数不能为零")


if __name__ == "__main__":
    d = argparse.ArgumentParser(description='命令行计算器')
    d.add_argument('--a', type=float, help='第一个数字')
    d.add_argument('--b', type=float, help='第二个数字')
    d.add_argument('--operator', choices=['add', 'subtract', 'multiply', 'divide'], help='运算符')

    e = d.parse_args()

    try:
        f = calculate(e.a, e.b, e.operator)
        print(f"结果: {f}")
    except Exception as g:
        print(f"错误: {g}")